package xps.and.uudaijia.userclient.view.activity;

import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import rx.Subscriber;
import xps.and.uudaijia.userclient.R;
import xps.and.uudaijia.userclient.data.baen.InformationBean;
import xps.and.uudaijia.userclient.data.net.UserNetWorks;
import xps.and.uudaijia.userclient.view.base.BaseActivity;

/**
 * Created by Administrator on 2017/7/27.
 */

public class WithdrawalsActivity extends BaseActivity {
    @BindView(R.id.actionbar_iv_back)
    ImageView actionbarIvBack;
    @BindView(R.id.balance_Text)
    TextView balanceText;
    @BindView(R.id.reflect_EditText)
    EditText reflectEditText;
    @BindView(R.id.reflect_Button)
    Button reflectButton;
    private static final int msgKey1 = 1;

    @Override
    protected int getLayout() {
        return R.layout.activity_withdrawals;
    }

    @Override
    protected void setData() {

    }

    @Override
    protected void init() {
        ButterKnife.bind(this);
        new TimeThread().start();
    }

    @OnClick({R.id.actionbar_iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.actionbar_iv_back:
                finish();
                break;
        }
    }

    void getInformation() {
        UserNetWorks.getInformation("", new Subscriber<InformationBean>() {

            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(InformationBean informationBean) {
                InformationBean.ReturnBodyBean returnBodyBean = informationBean.getReturn_body();
                if (informationBean.getReturn_code().equals("SUCCESS")) {
                    balanceText.setText("￥" + returnBodyBean.getBalance());
                }
            }
        });
    }

    public class TimeThread extends Thread {
        @Override
        public void run() {
            super.run();
            do {
                try {
                    Thread.sleep(1000);
                    Message msg = new Message();
                    msg.what = msgKey1;
                    mHandler.sendMessage(msg);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            } while (true);
        }
    }

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case msgKey1:
                    getInformation();
                    break;
                default:
                    break;
            }
        }
    };
}
